package com.heima.leadnews.artlite.listener;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.heima.leadnews.artlite.service.ApArticleConfigService;
import com.heima.model.common.article.pojo.ApArticleConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class listener {

    @Autowired
    ApArticleConfigService apArticleConfigService;
    @KafkaListener(topics = "new")
    public void  lis(ConsumerRecord<String,String>record){
        String key = record.key();
        String value = record.value();
        Long arid = Long.valueOf(key);
        boolean b = Boolean.parseBoolean(value);
        LambdaUpdateWrapper<ApArticleConfig> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ApArticleConfig::getArticleId,arid);
        updateWrapper.set(ApArticleConfig::getIsDown,!b);
        apArticleConfigService.update(updateWrapper);
    }

}
